{{template "header.html" .}}</head><body>
{{template "nav.html" (dict "navtab" "task" "authUser" .authUser )}}

<div class="container-fluid">
<nav aria-label="breadcrumb">
    <ol class="breadcrumb">

{{if gt .task.Id 0}}
<li class="breadcrumb-item"><a href="/task/thread/{{.task.Id}}">#{{.task.Id}} {{.task.Title}}</a></li>
<li class="breadcrumb-item active" aria-current="page">创建子任务</li>
{{else}}
<li class="breadcrumb-item">任务管理</li>
<li class="breadcrumb-item active" aria-current="page">新建任务</li>
{{end}}
    </ol>
</nav>
<hr />

{{if gt .task.Id 0}}
<div class="alert alert-danger" role="alert">
复制父任务创建子任务，要注意修改信息。
<ol>
    <li><b>状态，负责人</b> 是必填项。</li>
    <li><b>标题，内容</b> 根据情况自行修改。</li>
</ol>

</div>
{{end}}

</div>



<div class="container-fluid" id="task-add-form">
<input type="hidden" name="pid" value="{{.task.Id}}" />

<div id="taskfilter">
    <div class="row row-cols-lg-auto g-3 align-items-center mb-2">

<div class="col-12"><div class="input-group">
  <span class="input-group-text">标题</span>
  <input type="text" class="form-control" value="{{if eq .task.Title ""}}【一级模块】“二级模块”简要描述{{else}}{{.task.Title}}{{end}}" name="title" style="width: 800px;" />
</div></div>

<div class="col-12"><div class="input-group">

<select  itag="val" name="caty"
    class="form-select"
    value="{{.task.Caty}}"
>
    <option value="0">类型</option>
{{template "selection_map.html" (dict "values" .props.caty "selected" .task.Caty) }}
</select>

</div></div>

<div class="col-12"><div class="input-group">
<!-- 创建新任务 默认状态是12 -->
<select itag="val" name="status"
    class="form-select"
    value="{{.task.Status}}"
>
    <option value="0">状态</option>
{{template "selection_map.html" (dict "values" .props.status "selected" 12) }}
</select>

</div></div>

<div class="col-12"><div class="input-group">
<select itag="val" name="priority"
    class="form-select"
    value="{{.task.Priority}}"
>
    <option value="0">优先级</option>
{{template "selection_map.html" (dict "values" .props.priority "selected" .task.Priority) }}
</select>
<input type="text" class="form-control" itag="val" name="level" value="{{.task.Level}}" />

</div></div>

    </div>

    <div class="row row-cols-lg-auto g-3 align-items-center">
        <div class="col-12">

<div class="input-group">
    <select itag="val" name="project"
        class="form-select"
        value="{{.task.Project}}"
        onchange="onChangePro( this.value, '#filterTags', '版本' );"
    >
        <option value="0">项目</option>
{{template "selection_map.html" (dict "values" .projects "selected" .task.Project) }}
    </select>
    <select id="filterTags" itag="val" name="tag"
        class="form-select"
        value="{{.task.Tag}}"
    >
        <option value="0">版本</option>
{{template "selection_tag.html" (dict "values" .tags "selected" .task.Tag "filterId" .task.Project) }}
    </select>
</div>

        </div>

        <div class="col-12">

<div class="input-group">
    <!-- 创建新任务，必须选择手动选择部门 复制的任务也需要手动选择部门-->
    <div class="input-group-text">执行</div>
    <select itag="val" name="leader_dept"
        class="form-select"
        value="0"
        onchange="onChangeDepartment( this.value, '#filterLeader', '成员' );"
    >
        <option value="0">部门</option>
{{template "selection_map.html" (dict "values" .props.department "selected" 0) }}
    </select>
    <select id="filterLeader" itag="val" name="leader"
        class="form-select"
        value="0"
    >
        <option value="0">成员</option>
{{template "selection_user.html" (dict "values" .users "selected" 0 "filterId" 0) }}
    </select>
</div>

        </div>

        <div class="col-12">

<div class="input-group">
    <div class="input-group-text">验收</div>
    <select itag="val" name="checker_dept"
        class="form-select"
        value="{{.task.CheckerDept}}"
        onchange="onChangeDepartment( this.value, '#filterChecker', '成员' );"
    >
        <option value="0">部门</option>
{{template "selection_map.html" (dict "values" .props.department "selected" .task.CheckerDept) }}
    </select>
    <select id="filterChecker" itag="val" name="checker"
        class="form-select"
        value="{{.task.Checker}}"
    >
        <option value="0">成员</option>
{{template "selection_user.html" (dict "values" .users "selected" .task.Checker "filterId" .task.CheckerDept) }}
    </select>
</div>

        </div>

<div class="col-12"><div class="input-group">
    <div class="input-group-text">品控</div>
    <select itag="val" name="tester_dept"
        class="form-select"
        value="{{.task.TesterDept}}"
        onchange="onChangeDepartment( this.value, '#filterTester', '成员' );"
    >
        <option value="0">部门</option>
{{template "selection_map.html" (dict "values" .props.department "selected" .task.TesterDept) }}
    </select>
    <select id="filterTester" itag="val" name="tester"
        class="form-select"
        value="{{.task.Tester}}"
    >
        <option value="0">成员</option>
{{template "selection_user.html" (dict "values" .users "selected" .task.Tester "filterId" .task.TesterDept) }}
    </select>

</div></div>

<div class="col-12"><div class="input-group">
    <div class="input-group-text">时间</div>
    <input value="{{.task.StartAt | unixToDay}}" type="date" class="form-control" name="start_at" />
    <input value="{{.task.EndAt | unixToDay}}" type="date" class="form-control" name="end_at" />
</div></div>

    </div>
</div>
<!-- 快速修改 -->

        <hr />
{{if eq .task.Content ""}}
<textarea id="task-content" name="content"><p>【问题描述】</p>
<p>详细描述 需求/BUG 的具体情况，包括：</p>
<p>1. 什么情况下出现该问题</p>
<p>2. 具体的操作步骤</p>
<p>3. 实际结果</p>
<p>4. 预期结果</p>
<p><br></p>
<p>【复现步骤】</p>
<p>1. 进入...页面</p>
<p>2. 点击...按钮</p>
<p>3. 输入...信息</p>
<p>4. 观察到...现象</p>
<p><br></p>
<p>【截图或视频】</p>
<p>（可在此处上传问题截图或录屏）</p>
<p><br></p><p>【附加信息】</p>
<p>其他可能有助于问题排查的信息</p></textarea>
{{else}}
<textarea id="task-content" name="content">{{.task.Content|html}}</textarea>
{{end}}


<div class="mt-3"></div>
<div class="d-grid">
<button type="button" class="btn btn-danger btn-lg" onclick="_save()">
    <i class="fa-solid fa-floppy-disk"></i> 保存修改 </button>
</div>

</div>


{{template "footer.html" .}}

<script type="text/javascript">
var users = {{.users | json}};
var tags = {{.tags | json}};

$(document).ready(function() {
    initEditor("#task-content", false, 600);
});

var _isSubmitting = false;

function _save() {
    if (_isSubmitting) {
        return;
    }
    _isSubmitting = true;
    //五秒后解除
    setTimeout(function() {
        _isSubmitting = false;
    }, 5000);

    var data = getFormData("#task-add-form")
    data.start_at = new Date(data.start_at).getTime() / 1000;
    data.end_at = new Date(data.end_at).getTime() / 1000;

    if (data.start_at > data.end_at) {
        return showErrorToast("开始时间不能大于结束时间")
    }

    if (data.content.length < 10) {
        return $.alert({
            title: '提示信息',
            content: "<p>内容字数太少，不容易描述清楚问题。</p><p><br /></p><p>【问题描述】</p><p>详细描述 需求/BUG 的具体情况，包括：</p> <p>1. 什么情况下出现该问题</p> <p>2. 具体的操作步骤</p> <p>3. 实际结果</p> <p>4. 预期结果</p> <p><br></p> <p>【复现步骤】</p> <p>1. 进入...页面</p> <p>2. 点击...按钮</p> <p>3. 输入...信息</p> <p>4. 观察到...现象</p> <p><br></p> <p>【截图或视频】</p> <p>（可在此处上传问题截图或录屏）</p> <p><br></p><p>【附加信息】</p> <p>其他可能有助于问题排查的信息</p>",
            type: 'red',
        });
    }
    if (data.content.indexOf("data:image/png;base64") >= 0) {
        return showErrorToast('不正确的图片格式，不要从word、有道等软件中直接粘贴过来，建议使用ctl+shift+v');
    }
    if (data.content.indexOf('yne-bulb-block') >= 0) {
        return showErrorToast('不要从word、有道等软件中直接粘贴过来，使用ctl+shift+v')
    }

    if (data.title.length < 10) {
        return $.alert({
            title: '提示信息',
            content: "<p>标题字数不少于10字。</p><p>优秀示例：【一级模块】“二级模块”简要描述</p>",
            type: 'red',
        });
    }

    if (data.project == 0) {
        return showErrorToast("请选择项目")
    }
    if (data.tag == 0) {
        return showErrorToast("请选择版本")
    }
    if (data.leader == 0) {
        return showErrorToast("请选择执行成员")
    }
    if (data.checker == 0) {
        return showErrorToast("请选择验收成员")
    }
    if (data.tester == 0) {
        return showErrorToast("请选择品控成员")
    }
    if (data.caty == 0) {
        return showErrorToast("请选择类型")
    }
    if (data.priority == 0) {
        return showErrorToast("请选择优先级")
    }

    ajax("/task/save", data, function(r) {
        window.location.href = "/task/thread/" + r.id;
    })
}

</script>


</body></html>
